package com.huluobo.base.net

import com.blankj.utilcode.BuildConfig
import com.blankj.utilcode.util.ApiUtils.Api
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 *  Created by LC on 2024/9/12.
 */
private val client by lazy {
    OkHttpClient.Builder()
        .readTimeout(30, TimeUnit.SECONDS)
        .writeTimeout(30, TimeUnit.SECONDS)
        .connectTimeout(30, TimeUnit.SECONDS)
        .apply {
            //当什么什么时候
            if (BuildConfig.DEBUG) {
                addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            }
        }.build()
}

val retrofit by lazy {
    Retrofit.Builder()
        .baseUrl(Const.BaseURL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}

//对外暴露apiService的实例
inline fun <reified T> getService() = retrofit.create(ApiService::class.java)